package 周赛;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 所有子字符串中的元音 {
    //思路：https://leetcode-cn.com/problems/vowels-of-all-substrings/solution/dan-du-ji-suan-mei-ge-yuan-yin-de-chu-xi-eyjf/
    public static long countVowels1(String word) {
        long num = 0;
        List<Character> list = Arrays.asList('a', 'e', 'i', 'o', 'u');
        for (int i = 0; i < word.length(); i++) {
            if (list.contains(word.charAt(i))){
                //整型转化为长整型时，做强转
                num += (long)(i+1)*(word.length()-i);
            }
        }
        return num;
    }

    public static long countVowels(String word) {
        char[] chars = word.toCharArray();
        long num = 0;
        List<Character> list = Arrays.asList('a', 'e', 'i', 'o', 'u');
        for (int i = 0; i < word.length(); i++) {
            int cur = 0;
            for (int j = i; j < word.length(); j++) {
                if (list.contains(chars[j])){
                    cur++;
                }
                num+=cur;
            }
        }
        return num;
    }

    public static void main(String[] args) {
        System.out.println(countVowels("noosabasboosa"));
    }
}
